include makefile.include
# 默认目标
all: app driver copytarget

help:
	@echo "make {all|app|driver|copysource|copytarget}"

app:
	@echo "Building application..."
	

	@for i in $(makeTarget); do
		@make -C $$i Q="@"
	fi

    # 创建目标目录（如果不存在）
	@if [ ! -d "$(targetpath)" ]; then \
        mkdir -p "$(targetpath)"; \
    fi

# 驱动
driver:
	@echo "Building drivers..."
	@for drv in $(driverDir)/*; do \
    	make -C $$drv; \
        cp $$drv/*.ko $(driverspath); \
    	echo "Driver $$(basename $$drv) built and copied."; \
	done

#复制编译生成的目标文件
copytarget:
	@if [ ! -d "$(targetpath)" ]; then \
        mkdir -p "$(targetpath)"; \
    fi
	@for i in $(targetcontents); do \
		chmod 755 $$i;\
		cp $$i $(targetpath);\
	done
	@if [ ! -d "$(libpath)" ]; then \
        mkdir -p "$(libpath)"; \
    fi
	@for i in $(privatelib); do \
		chmod 755 $$i;\
		cp $$i $(libpath);\
	done

#复制需移植的lib文件
copysource:
	@for i in $(sourcelibcontent); do\
		cp $$i/* $(libpath) -af;\
	done

clean:
	@echo "Cleaning up..."
	@make -C $(appDir) clean
	@for drv in $(driverDir)/*; do \
        make -C $$drv clean; \
	done
	@rm -rf $(targetpath)/*
	@rm -rf $(driverspath)/*.ko
	@rm -rf $(libpath)/*

distclean:
	@make -C $(appDir) clean
.PHONY: all app driver clean copysource copytarget help
